//
//  LBFilter.h
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 11/14/12.
//  Copyright (c) 2012 UIT. All rights reserved.
//

#ifndef OpenGLGame_LBFilter_h
#define OpenGLGame_LBFilter_h

#include "LBProgram.h"
#include "LBStruct.h"
class LBTexture;
class LBFramebuffer;

/**
 Variable name default in shader:
 position   : vertices array
 texCoor    : texure coordinate
 texture    : texture input
 */

/**
 To create a derived class of LBFilter, example LBDerivedFilter. In LBDerivedFilter.h, define variables for new parametters, and new attributes/uniforms for those parametters. Also, create setter and getter function define for that parametters. 
 In LBDerivedFilter.mm, create constructor, call init(...) with new shader, and get attributes/uniforms index in those constructor. With each setters, set value for each parametter and send value to shader program use glUniform... or glVertexAttribPointer and glEnableVertexAttribArray.
 */
class LBFilter {

protected:
    LBProgram* program;
    
    LBFramebuffer* fbo;
    LBTexture* outputTexture;
    
    GLuint textureUniform;
    GLuint texCoorAttribute;
    GLuint positionAttribute;
    GLuint mWorldUniform;
    GLuint mProjectionUniform;    
    LBFilter* targetFilter;
    float x, y;
    float scaleX, scaleY;
    
public:
    LBTexture* texture;
    
    LBFilter();
    virtual void init(char* vShaderStr, char* fShaderStr);
    virtual void init(char* vShaderStr, char* fShaderStr, LBTexture* texture);
    virtual ~LBFilter();
    
    void setLocationAndScale(float x, float y, float scaleX, float scaleY);
    void setLocation(float x, float y);
    LBFilter* addTarget(LBFilter* targetFilter);
    void addTargetToFinalTarget(LBFilter* targetFilter);
    void untargetAll();
    
    virtual void render();
    virtual void renderTexture(int x, int y, float scaleX, float scaleY);
    
    //getter and setter
    virtual void setTexture(LBTexture* texture);
    LBTexture* getTexture();
    LBTexture* getOutputTexture();
    LBTexture* getFinalOutputTexture();
};

#endif
